/**
 * 
 */
package neptune.console.cli.commands;

import java.util.List;

import neptune.console.CLCommand;
import neptune.console.NeptuneCLI;
import neptune.manager.model.cluster.PhysicalNode;
import neptune.manager.model.topology.Cpu;
import neptune.manager.model.topology.IPAddress;
import neptune.manager.model.topology.MACAddress;
import neptune.manager.model.topology.NetworkInterface;
import neptune.manager.model.topology.OperativeSystem;

import org.springframework.stereotype.Component;

/**
 * @author Roberto Bifulco [info@robertobifulco.it]
 * 
 */
@Component
public class AddPhysicalMachine implements CLCommand {
	@Override
	public String getCommandHelp() {
		return "Adds a physical machine to the Neptune managed infrastructure";
	}

	@Override
	public String getCommandName() {
		return "addPM";
	}

	@Override
	public void processCommand(List<String> args) throws Exception {
		String pmName = args.remove(0);
		String ipAddress = args.remove(0);
		String rootPwd = args.remove(0);

		PhysicalNode pm = new PhysicalNode("", "", pmName);

		IPAddress ipAddr = new IPAddress(4, ipAddress, "255.255.255.0");
		ipAddr.setControlAddress(true);

		NetworkInterface netIf = new NetworkInterface("eth0",
				NetworkInterface.PHYSICAL_INTERFACE, new MACAddress(""));
		netIf.addIpAddress(ipAddr);
		pm.addNetworkInterface(netIf);

		OperativeSystem os = new OperativeSystem();
		os.setAdminUsername("root");
		os.setAdminPassword(rootPwd);

		pm.setOperativeSystem(os);

		Cpu cpu = new Cpu();
		pm.setCpu(cpu);

		NeptuneCLI.getNeptune().addPhysicalMachine(pm);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see neptune.console.CLCommand#getParamsDescription()
	 */
	@Override
	public String getParamsDescription() {
		return "<pm_name> <ip_address> <root_pwd>";
	}
}
